package com.sunnada.edu.system.pub.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.sunnada.edu.system.pub.util.Utils;

/**explain 区域树管理
 * @author cbin 2014-12-04
 * version 1.0
 */
public class TreeMethods {
	
	/**
	 * 设置区域树
	 * @param list 区域结果集
	 * @return treeList
	 */
	public static List<Tree> setTreeProperty(List<Map<String,Object>> list){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("AREA_CODE").toString()));
				tree.setParentCode((list.get(i).get("PARENT_CODE").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				if((list.get(i).get("ALL_AREA_NAME")==null)) {
					tree.setAllAreaName("");
				}else {
					tree.setAllAreaName((list.get(i).get("ALL_AREA_NAME").toString()));
				}
				tree.setName(list.get(i).get("AREA_NAME").toString());
				tree.setType(list.get(i).get("AREA_TYPE").toString());
				if(list.get(i).get("IS_LEAF").toString().equals("0")){
					tree.setIsParent(false);
				}else{
					tree.setIsParent(true);
				}
				treeList.add(tree);
			}
		}
		return treeList;
	}
	/**
	 * 设置区域树
	 * @param list 区域结果集
	 * @param nocheck 是否隐藏父节点复选框
	 * @return treeList
	 */
	public static List<Tree> setTreeProperty(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("AREA_CODE").toString()));				
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("AREA_NAME").toString());
				//tree.setType(list.get(i).get("AREA_TYPE").toString());
				/*if(list.get(i).get("IS_LEAF").toString().equals("0")){
					tree.setIsParent(false);
				}else{
					tree.setIsParent(true);
					tree.setNocheck(nocheck);
				}*/
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}
	/**
	 * 设置区域树
	 * @param list 区域结果集
	 * @param nocheck 是否隐藏父节点复选框
	 * @return treeList
	 */
	public static List<Tree> setOrgTreeProperty(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("ORG_CODE").toString()));				
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("ORG_NAME").toString());
				//tree.setType(list.get(i).get("AREA_TYPE").toString());
				/*if(list.get(i).get("IS_LEAF").toString().equals("0")){
					tree.setIsParent(false);
				}else{
					tree.setIsParent(true);
					tree.setNocheck(nocheck);
				}*/
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}
	public static List<Tree> setTreePropertyForModule(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("MODULE_CODE").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("MODULE_NAME").toString());				
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}
	
	public static List<Tree> setTreePropertyForDept(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("REC_ID").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("DEPT_NAME").toString());				
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}
	/**
	 * 设置角色树
	 * @param list 角色结果集
	 * @return treeList
	 */
	public static List<Tree> setTreePropertyForRole(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("REC_ID").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("ROLE_NAME").toString());				
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}
	
	public static List<Tree> setTreePropertyForGrade(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("REC_ID").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("GRADE_NAME").toString());	
				if (Utils.isNotNull(list.get(i).get("GRADE_TYPE"))) {
					tree.setType(list.get(i).get("GRADE_TYPE").toString());	
				}
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}

	public static List<Tree> setTreePropertyForLetterFolder(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("REC_ID").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("FOLDER_NAME").toString());
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}
	
	public static List<Tree> setGroupTreePropertyForLetterFolder(List<Map<String,Object>> list,Boolean nocheck){
		List<Tree> treeList = new ArrayList<Tree>();
		if(null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Tree tree = new Tree();
				tree.setCode((list.get(i).get("REC_ID").toString()));
				tree.setId((list.get(i).get("REC_ID").toString()));
				tree.setName(list.get(i).get("GROUP_NAME").toString());
				tree.setIsParent(true);
				treeList.add(tree);
			}
		}
		return treeList;
	}

}
